﻿@{
    Layout = "~/_SiteLayout.cshtml";

    string name = string.Empty;

    string query1 = string.Format("&appid={0}&tabid={1}", Request.QueryString["appid"], Request.QueryString["tabid"]);

    Business.Platform.WorkFlowButtons bworkFlowButtons = new Business.Platform.WorkFlowButtons();
    IEnumerable<Data.Model.WorkFlowButtons> workFlowButtonsList;

    if(IsPost)
    {
        if(!Request.Form["DeleteBut"].IsNullOrEmpty())
        {
            string ids = Request.Form["checkbox_app"];
            foreach(string id in ids.Split(','))
            {
                Guid bid;
                if(!id.IsGuid(out bid))
                {
                    continue;
                }
                var but = bworkFlowButtons.Get(bid);
                if(but!=null)
                {
                    bworkFlowButtons.Delete(bid);
                    Business.Platform.Log.Add("删除了流程按钮", but.Serialize(), Business.Platform.Log.Types.流程相关);
                }
            }
            bworkFlowButtons.ClearCache();
           
        }
        workFlowButtonsList = bworkFlowButtons.GetAll();
        
        if(!Request.Form["Search"].IsNullOrEmpty())
        {
            name = Request.Form["Name"];
            if (!name.IsNullOrEmpty())
            {
                workFlowButtonsList = workFlowButtonsList.Where(p => p.Title.IndexOf(name) >= 0);
            }
        }
    }
    else
    {
        workFlowButtonsList = bworkFlowButtons.GetAll();
    }
}

<form action="" method="post" >
<div class="querybar">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td>
                名称：<input type="text" class="mytext" style="width:190px;" id="Name" name="Name" value="@name" />
                <input type="submit" name="Search" value="查询" class="mybutton" />
            </td>
        </tr>
    </table>
</div>
<div class="toolbar" style="margin-top:0; border-top:0;">
    <a href="javascript:void(0);" onclick="add();return false;"><span style="background-image:url(/Images/ico/folder_classic_stuffed_add.png);">添加按钮</span></a>
    <span class="toolbarsplit">&nbsp;</span>
    <input type="submit" style="display:none;" value="d" id="DeleteBut" name="DeleteBut" />
    <a href="javascript:void(0);" onclick="del();return false;"><span style="background-image:url(/Images/ico/folder_classic_stuffed_remove.png);">删除所选</span></a>
</div>
<table cellpadding="0" cellspacing="1" border="0" class="listtable">
    <thead>
        <tr>
            <th><input type="checkbox" onclick="checkAll(this.checked);" style="vertical-align:middle;" />按钮名称</th>
            <th>按钮图标</th>
            <th>按钮说明</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
    @foreach (var button in workFlowButtonsList.OrderBy(p=>p.Sort))
    {
        <tr>
            <td><input type="checkbox" value="@button.ID" name="checkbox_app" style="vertical-align:middle;" />@button.Title</td>
            <td align="center">@if(!button.Ico.IsNullOrEmpty()){<img src='@button.Ico' alt='' />}</td>
            <td>@button.Note</td>
            <td>
                <a class="editlink" href="javascript:edit('@button.ID');">编辑</a>
            </td>
        </tr>
    }
    </tbody>
</table>
<script type="text/javascript">
    var appid = '@Request.QueryString["appid"]';
    var iframeid = '@Request.QueryString["tabid"]';
    var dialog = top.mainDialog;
    function add()
    {
        dialog.open({ id: "window_" + appid.replaceAll('-', ''), title: "添加按钮", width: 700, height: 420, url: '/Platform/WorkFlow/Buttons/Edit?1=1' + '@query1', openerid: iframeid });
    }
    function edit(id)
    {
        dialog.open({ id: "window_" + appid.replaceAll('-', ''), title: "编辑按钮", width: 700, height: 420, url: '/Platform/WorkFlow/Buttons/Edit?id=' + id + '@query1', openerid: iframeid });
    }
    function checkAll(checked)
    {
        $("input[name='checkbox_app']").prop("checked", checked);
    }
    function del()
    {
        if ($(":checked[name='checkbox_app']").size() == 0)
        {
            alert("您没有选择要删除的项!");
            return false;
        }
        if (!confirm('您真的要删除所选按钮吗?'))
        {
            return false;
        }
        $("#DeleteBut").click();
        return true;
    }
</script>
</form>